package com.demo.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;

public class ProxyTest2 {

	public static void main(String[] args) {
		
		List list = (List)Proxy.newProxyInstance(ArrayList.class.getClassLoader(),
				ArrayList.class.getInterfaces(), 
				new InvocationHandler() {
				ArrayList target = new ArrayList();
					@Override
					public Object invoke(Object proxy, Method method, Object[] args)
							throws Throwable {
						long startTime = System.currentTimeMillis();	
						Object rev = method.invoke(target, args);
						long endTime=System.currentTimeMillis();
						System.out.println("执行时间:"+ (endTime-startTime) );
						return rev;
					}
				}
				);
		System.out.println(list.getClass().getName());
		list.add(100);
		list.add("xxxx");
		System.out.println(list.size());
	}
}
